﻿using System.Collections.Generic;
using ConfigGen.ConsoleApp.Core.CommandLineOptionCore;
using ConfigGen.Core;

namespace ConfigGen.ConsoleApp.Core.CommandLineOptions
{
    /// <summary>
    /// Console argument handler to handle the "output encoding" command line option. This processor is responsible for setting the
    /// <see cref="Preferences.OutputEncoding"/> property on the settings object.
    /// </summary>
    public class OutputEncoding : ICommandLineOption<ConsoleAppPreferences>
    {
        private string _specifiedOutputEncoding;

        #region ICommandLineOption<Preferences> Members

        /// <summary>
        /// Gets the short name of the command line argument, without the leading hyphen; for this processor: "oe".
        /// </summary>
        /// <value>"oe"</value>
        public string ShortName
        {
            get { return "oe"; }
        }

        /// <summary>
        /// Gets the long name of the command line argument, without the leading hyphens; for this processor: "output-encoding"
        /// </summary>
        /// <value>"output-encoding"</value>
        public string LongName
        {
            get { return "output-encoding"; }
        }

        /// <summary>
        /// Gets a help string containing the args usage for this processor: "&lt;output-encoding&gt;"
        /// </summary>
        /// <value>"&lt;output-encoding&gt;"</value>
        public string ArgsUsage
        {
            get { return "<output-encoding>"; }
        }

        /// <summary>
        /// Gets help text for this command line option.
        /// </summary>
        /// <value>Help text</value>
        public string HelpText
        {
            get
            {
                return
                    @"Instructs ConfigGen to write output files with the specified encoding. Valid values are 'A' (ASCII), 'U8' (UTF-8) and 'U16' (UTF-16, Little Endian). NOTE: this can only be used in conjunction with the 'remove root element' setting.";
            }
        }

        /// <summary>
        /// Applies the option represented by this instance to the supplied settings instance.
        /// </summary>
        /// <param name="settings">The settings object.</param>
        public void ApplyOptionToSettings(ConsoleAppPreferences settings)
        {
            settings.OutputEncoding = _specifiedOutputEncoding;
        }

        /// <summary>
        /// Processes the argument queue by consuming (dequeuing) any arguments used by this instance. For this type of processor, a single argument is consumed
        /// by this method.
        /// </summary>
        /// <param name="args">Args queue from which to consume args</param>
        public void ConsumeArgumentsFromQueue(Queue<string> args)
        {
            _specifiedOutputEncoding = args.Dequeue();
        }

        #endregion
    }
}